package com.aaa.web.service.dept;

import com.aaa.web.dao.dept.DeptDaoImpl;
import com.aaa.web.dao.dept.Impl.DeptDao;
import com.aaa.web.entity.Dept;
import com.aaa.web.service.dept.Impl.DeptService;
import java.util.List;

/**
 * @ProjectName Java_web_demo_20230302
 * @Author 李江波
 * @Date 2023/03/02 上午 10:28
 * @Version 1.0.0
 * @Description
 */
public class DeptServiceImpl implements DeptService {
    //引入Dao层对象
    private DeptDao deptDao = new DeptDaoImpl();

    @Override
    public List<Dept> queryByPage(int pageNo, int pageSize, Dept dept) {
        //计算开始值
        int start = (pageNo-1)*pageSize;
        return deptDao.queryByPage(start,pageSize,dept);
    }

    @Override
    public int queryTotal(Dept dept) {
        return deptDao.queryTotal(dept);
    }

    @Override
    public List<Dept> queryAll() {
        return deptDao.queryAll();
    }

    @Override
    public Dept queryById(int deptNo) {
        //根据编号查询部门列表
        List<Dept> depts = deptDao.queryById(deptNo);
        System.out.println(depts);
        //判断集合是否为null
        if (depts!=null&&depts.size()>0){
            for (Dept dept : depts) {
                return dept;
            }
        }
        return null;
    }

    @Override
    public int add(Dept dept) {
        return deptDao.add(dept);
    }

    @Override
    public int update(Dept dept) {
        return deptDao.update(dept);
    }

    @Override
    public int deleteById(int deptNo) {
        return deptDao.deleteById(deptNo);
    }
}
